class_name Shot
extends Line2D


# 子弹穿过屏幕的持续时间（毫秒）
@export var duration_shot_across_screen: float

# 射线中点的高度
var height: float
# 射线的目标距离，正值表示向右，负值表示向左
var target_distance: float

var duration_shot: float
var time_start: float


func _ready():
	time_start = Time.get_ticks_msec()
	duration_shot = absf(target_distance) * duration_shot_across_screen / get_viewport_rect().size.x

	add_point(Vector2(0.0, -height), 0)
	add_point(Vector2(target_distance, -height), 1)



func _process(_delta: float):
	var elapsed := Time.get_ticks_msec() - time_start
	var progress := elapsed / duration_shot
	var new_x := lerpf(0.0, target_distance, progress)
	set_point_position(0, Vector2(new_x, -height))
	if progress >= 1.0:
		queue_free()
